﻿// <copyright file="NodeExtensions.cs" company="Auros Ltd.">
//     Copyright (c) Auros Ltd. All rights reserved.
// </copyright>

namespace Auros.Categorisation
{
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// Class of extension methods for umbraco.NodeFactory.Node.
    /// </summary>
    public static class NodeExtensions
    {
        /// <summary>
        /// Gets the categories associated with the current node.
        /// </summary>
        /// <param name="currentNode">The current node.</param>
        /// <param name="propertyAlias">The alias of the property which is used for storing the associated category IDs.</param>
        /// <returns>Collection of category objects.</returns>
        public static IEnumerable<Category> GetCategories(this umbraco.NodeFactory.Node currentNode, string propertyAlias)
        {
            return NodeHelpers.GetCategoriesForNode(currentNode, propertyAlias);
        }

        /// <summary>
        /// Determines whether the current node has the specified category assigned to it.
        /// </summary>
        /// <param name="currentNode">The current node.</param>
        /// <param name="propertyAlias">The alias of the property which is used for storing the associated category IDs.</param>
        /// <param name="categoryId">The ID of the category which is to be checked.</param>
        /// <returns>
        /// <c>True</c> if the current node has the specified category assigned; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasCategoryAssigned(this umbraco.NodeFactory.Node currentNode, string propertyAlias, int categoryId)
        {
            return NodeHelpers.NodeHasCategoryAssigned(currentNode, propertyAlias, categoryId);
        }

        /// <summary>
        /// Gets the descendant nodes from the current node.
        /// </summary>
        /// <param name="node">The current node.</param>
        /// <param name="func">The function to filter nodes.</param>
        /// <param name="includeDescendantsOfNonMatches">If set to <c>true</c> then descendants of non-matching nodes will be included in the query.</param>
        /// <returns>Collection of nodes.</returns>
        public static IEnumerable<umbraco.NodeFactory.Node> GetDescendantNodes(this umbraco.NodeFactory.Node node, Func<umbraco.NodeFactory.Node, bool> func = null, bool includeDescendantsOfNonMatches = true)
        {
            return NodeHelpers.GetDescendantNodes(node, func, includeDescendantsOfNonMatches);
        }
    }
}